package pers.mine.frontUser.service.impl;

import java.util.List;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import pers.mine.dao.FrontHateWordMapper;
import pers.mine.dao.FrontTaskMapper;
import pers.mine.dao.QueryMapper;
import pers.mine.frontUser.service.FrontHateWordService;
import pers.mine.nook.PageInfo;
import pers.mine.nook.QueryHandler;
import pers.mine.nook.SysInfo;
import pers.mine.po.FrontHateWord;
import pers.mine.po.FrontTask;

/**
 * TODO 
 * @author Mine
 * @since 2017年6月9日_下午9:13:09
 */
@Service
public class FrontHateWordServiceImpl extends BaseServiceImpl<FrontHateWord> implements
		FrontHateWordService {
	private static final Log logger = LogFactory
			.getLog(FrontHateWordServiceImpl.class);
	@Autowired
	private QueryMapper queryMapper;

	private FrontHateWordMapper frontHateWordMapper;

	@Autowired
	public void setFrontHateWordMapper(FrontHateWordMapper frontHateWordMapper) {
		this.frontHateWordMapper = frontHateWordMapper;
		super.setBaseMapper(frontHateWordMapper);// 给BaseServiceImpl赋值
	}
	
	@Override
	public PageInfo<FrontHateWord> findSomeByQueryHandler(
			QueryHandler queryHandler) throws Exception {
		List<FrontHateWord> list = queryMapper.queryFrontHateWord(queryHandler);
		long rootSize = 0;
		int nowPage = 1;
		int pageSize = SysInfo.PAGE_INFO_DEFAULT_SIZE;
		if (queryHandler == null || queryHandler.getLimitSentence() == null) {// 没分页
			if (logger.isDebugEnabled()) {
				logger.debug("构造PageInfo:未指定分页信息...");
			}
			if (list != null) {
				rootSize = list.size();
			}
		} else {
			nowPage = queryHandler.getPageNumber();
			pageSize = queryHandler.getPageSize();
			// 获取总记录数
			rootSize = queryMapper.findLastRows();
			if (logger.isDebugEnabled()) {
				logger.debug("构造PageInfo,分页信息:rootSize=" + rootSize
						+ ",nowPage=" + nowPage + ",pageSize=" + pageSize);
			}
		}
		PageInfo<FrontHateWord> pageInfo = new PageInfo<FrontHateWord>((int) rootSize,
				nowPage, pageSize);
		pageInfo.setBasePageList(list);
		return pageInfo;
	}

}
